<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/common/template.xhtml">

	<ui:define name="pageContent">
		<h:form>
			<table class="mainTable">
				<tr>
					<td><h:outputLabel value="Регистрационен номер на автомобила*">
							<h:inputText id="platenum"
								value="#{dobavqneNaKlientskaPoru4ka.vehicle.plateNumber}"
								maxlength="8" readonly="true" />
						</h:outputLabel></td>
					<td><h:commandButton value="Избери" class="regButton"
							style="width:80px;height:40px;margin-left:20px;margin-top:20px;"
							action="#{dobavqneNaKlientskaPoru4ka.chooseAvtomobil()}" /></td>
				</tr>
			</table>
			<h:panelGroup
				rendered="#{not empty dobavqneNaKlientskaPoru4ka.client.person}">
				<!-- ако клиентът е физическо лице се изчертава това -->
				<table class="mainTable">
					<tr>
						<td><h:outputLabel value="Име на клиент">
								<h:inputText id="personname"
									value="#{dobavqneNaKlientskaPoru4ka.client.person.name}"
									maxlength="50" required="false"
									requiredMessage="задължително поле!" readonly="true" />
							</h:outputLabel></td>
						<td><h:outputLabel value="Фамилия на клиент">
								<h:inputText id="personfamily"
									value="#{dobavqneNaKlientskaPoru4ka.client.person.family}"
									maxlength="50" required="false"
									requiredMessage="задължително поле!" readonly="true" />
							</h:outputLabel></td>
					</tr>
				</table>
			</h:panelGroup>

			<h:panelGroup
				rendered="#{not empty dobavqneNaKlientskaPoru4ka.client.company}">
				<!-- ако клиентът е юридическо лице се изчертава това -->
				<table class="mainTable">
					<tr>
						<td><h:outputLabel value="Наименование на фирма">
								<h:inputText id="companyname"
									value="#{dobavqneNaKlientskaPoru4ka.client.company.name}"
									maxlength="100" required="false"
									requiredMessage="задължително поле!" readonly="true" />
							</h:outputLabel></td>
					</tr>
				</table>
			</h:panelGroup>
			<br />

			<table class="mainTable" style="margin-bottom: 10px;">
				<tr>
					<td><h:outputLabel value="Автомобилът е приет за ремонт*">
							<h:selectBooleanCheckbox
								value="#{dobavqneNaKlientskaPoru4ka.inAutoservice}" />
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="Използвай доклад от диагностика:">
							<h:commandButton value="Избери"
								action="#{dobavqneNaKlientskaPoru4ka.chooseDiagnostika()}" class="inTableButton"/>
						</h:outputLabel></td>
				</tr>
				<tr>
					<td><h:outputLabel value="Услуги, които ще бъдат извършени:">
							<h:commandButton value="Избери"
								action="#{dobavqneNaKlientskaPoru4ka.chooseUsluga()}" class="inTableButton"/>
						</h:outputLabel></td>
				</tr>
			</table>
			<div id="scroolTable">
				<!-- scroll bar -->
				<h:dataTable value="#{dobavqneNaKlientskaPoru4ka.spisukUslugi}"
					var="curr" rowClasses="notSelectedRow">

					<h:column>
						<f:facet name="header">Наименование на услугата</f:facet>
				#{curr.clService.service.description}
			</h:column>

					<h:column>
						<f:facet name="header">Време за извършване (часа)</f:facet>
				#{curr.serviceDuration}
			</h:column>

					<h:column>
						<f:facet name="header">Цена на час</f:facet>
				#{curr.clService.priceHour}
			</h:column>

					<h:column>
						<f:facet name="header">Общо</f:facet>
				#{curr.fullPrice}
			</h:column>

					<h:column>
						<f:facet name="header">Кой заплаща услугата</f:facet>
				#{dobavqneNaKlientskaPoru4ka.getWhoWillPay(curr.clService.whoPays) }
			</h:column>

					<h:column>
						<f:facet name="header">Премахни</f:facet>
						<h:commandButton
							action="#{dobavqneNaKlientskaPoru4ka.deleteUsluga(curr)}"
							value="Премахни" class="inTableButton"/>
					</h:column>
				</h:dataTable>
			</div>
			<br />
			<table class="mainTable" style="margin-bottom: 10px;">
				<tr>
					<td><h:outputLabel
							value="Резервни части, които трябва ще бъдат вложени:">
							<h:commandButton value="Избери"
								action="#{dobavqneNaKlientskaPoru4ka.chooseSparePart()}" class="inTableButton"/>
						</h:outputLabel></td>
				</tr>
			</table>
			<!-- TODO: може ли да се сложи scroll bar по Y с определен брой редове 
	    Оцветяване на ред с липсващи резервни части-->
			<div id="scroolTable">
				<!-- scroll bar -->
				<h:dataTable
					value="#{dobavqneNaKlientskaPoru4ka.spisukRezervni4asti}"
					var="curr" rowClasses="notSelectedRow">

					<h:column>
						<f:facet name="header">Група на резервната част</f:facet>
				#{curr.clPart.sparePart.sparePartGroup.description}
			</h:column>

					<h:column>
						<f:facet name="header">Име на резервната част</f:facet>
				#{curr.clPart.sparePart.name}
			</h:column>

					<h:column>
						<f:facet name="header">Нужно количество</f:facet>
						<h:outputText value="#{curr.clPart.quantity}"
							rendered="#{!curr.editing}" />
						<h:inputText value="#{curr.clPart.quantity}"
							rendered="#{curr.editing}">
							<f:validateDoubleRange minimum="0.001" />
						</h:inputText>
					</h:column>

					<h:column>
						<f:facet name="header">Мерна единица</f:facet>
				#{curr.clPart.sparePart.measuringUnit}
			</h:column>

					<h:column>
						<f:facet name="header">Налично количество</f:facet>
				#{curr.quantityAvailable}
			</h:column>

					<h:column>
						<f:facet name="header">Единична цена</f:facet>
				#{curr.clPart.priceUnit}
			</h:column>

					<h:column>
						<f:facet name="header">Общо</f:facet>
				#{curr.fullPrice}
			</h:column>

					<h:column>
						<f:facet name="header">Кой заплаща услугата</f:facet>
				#{dobavqneNaKlientskaPoru4ka.getWhoWillPay(curr.clPart.whoPays)}
			</h:column>

					<h:column>
						<f:facet name="header">Промени</f:facet>
						<h:commandLink
							action="#{dobavqneNaKlientskaPoru4ka.toggleEditSparePartForClientOrder(curr)}"
							value="Промени" />
					</h:column>

					<h:column>
						<f:facet name="header">Премахни</f:facet>
						<h:commandLink
							action="#{dobavqneNaKlientskaPoru4ka.deleteSparePart(curr)}"
							value="Премахни" />
					</h:column>

				</h:dataTable>
			</div>
			<br />
			<table class="buttonTable"
				style="margin-top: 30px; margin-left: 0px;">
				<tr>
					<td><h:outputText
							value="Обща цена на поръчката: #{dobavqneNaKlientskaPoru4ka.clientOrderPrice}" />
					</td>
				</tr>
				<tr>
					<td><h:commandButton value="Добави" class="regButton"
							style="width:80px;height:40px;"
							action="#{dobavqneNaKlientskaPoru4ka.addClientOrder()}" /> <br />

						<h:outputText value="#{dobavqneNaKlientskaPoru4ka.errorMessage}" />
					</td>
				</tr>
			</table>
		</h:form>
	</ui:define>

</ui:composition>
</html>